﻿/*
 * TcpStream.h
 *
 */
#ifndef __GDK_TCPSTREAM_H__
#define __GDK_TCPSTREAM_H__

#include <gdk/core/Types.h>
#include <gdk/core/IO.h>
#include <gdk/core/MemoryStream.h>
#include <gdk/net/TcpSecureConnection.h>



namespace gdk
{


	class GDK_NET_EXPORT TcpStream : public TcpSecureConnection, public IO
	{
		DECLARE_CLASS_HANDLE(TcpStream)
		DECLARE_CLASS_INSTANCE(TcpStream)

	private:
		enum
		{
			CACHE_SIZE = SecureSession::BUFFERSIZE,
		};

	private:
		MemoryStream::Handle	_writeCache;
		ssize_t					_writeBeginPointer;
		ssize_t					_writeEndPointer;
		char					_writeBuffer[CACHE_SIZE];


	protected:
		TcpStream(void);
		~TcpStream(void);

	public:
		int flush(void);

	public:
		virtual void onTick(uint32_t timeSinceLastTick);
		virtual bool attach(SOCKET s);
		virtual ssize_t send(const void *data, ssize_t size);
		virtual void close(void);

	public:
		virtual ssize_t available(void) const;
		virtual ssize_t peek(void *buf, ssize_t size) const;
		virtual ssize_t read(void *buf, ssize_t size);
		virtual ssize_t write(const void *data, ssize_t size);
	};







}//namespace gdk



#endif /*__GDK_TCPSTREAM_H__*/
